<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <!--{include file='comm/header.tpl'}-->
    <title>签到活动添加</title>
    <!--{include file='comm/comm_cal.tpl'}-->
</head>
<body>

<style>
    .hideClass{
        display:none;
    }
</style>
<div style="width:100%">
    <div class="items clearfix">
        <h2 style="" class="tal">
            正在操作：签到活动添加
        </h2>
        <div class="items2">
            <div>
                <form id="selector_form" onsubmit="return false;">

                    <table>
                        <tr>
                           <td class='tar'>
                                活动主题：
                                </td>
                            <td>
                                <input type='text'>
                                </td>
                            </tr>
                        <tr>
                           <td class='tar'>
                               活动时间：
                                </td>
                            <td>
                                <input  type='text' name='startDate' id='startDate'>
                                ~
                                <input  type='text' name='endDate' id='endDate'>
                                </td>
                            </tr>
                        <tr>
                            <td class='tar'>
                                活动描述：
                                </td>
                            <td>
                                <textarea></textarea>
                                </td>
                            </tr>
                        <tr>
                            <td class='tar'>
                                活动礼品：
                                </td>
                            <td>
                                <input id="gift" type='radio' value='1' onclick="Signed.goodsType(this,1)"  name = 'gift' >&nbsp;积分&nbsp;
                                <input id="giftPro" type='radio' value='2' onclick="Signed.goodsType(this,2)"  name = 'gift' >&nbsp;赠品
                                </td>
                            </tr>
                        <tr>
                            <td class='tar'>
                                活动类型：
                            </td>
                            <td>
                                <input type='radio' value='1'  name = 'conSigned' onclick="Signed.signedType(this,'conType')" >&nbsp;连续签到&nbsp;
                                <input type='radio' value='2'  name = 'conSigned' onclick="Signed.signedType(this,'accType')">&nbsp;累计签到
                            </td>
                        </tr>

                        <tr>
                            <td>&nbsp;</td>
                            <td>

                                <div id="hiddenBox">

                                </div>

                                <div id = 'selectmer' style="width:550px;margin-top: 18px;">
                                    <table id="flex" style="display:none"></table>
                                </div>

                            </td>
                        </tr>
                        </table>

                </form>
            </div>
        </div>
    </div>

    <div class="bottom_fixbox">
        <div class="rectbox tac">
            <input type="button" class="btn" onclick="Signed.check();" value="保存" />&nbsp;&nbsp;&nbsp;
            <input type="button" class="btn" onclick="E.closeWindows();" value="关闭" />
        </div>
    </div>


</div>
<script type="text/javascript">
//表格对象
var table_obj = {'page' : '', 'total' : '', 'rows' : []};

var mark = 0;
var accTypeArr = new Array();
var mark1 = 0;
var conTypeArr = new Array();
var mark2 = 0;
var accTypeGoodsArr = new Array();
var mark3 = 0;
var conTypeGoodsArr = new Array();

//微信互动活动列表
$("#flex").flexigrid({
    dataType: "json",
    colModel : [
        {display: "当月连续签到/当月累计签到", width : 200, align:'left'},
        {display: "赠送积分/赠送礼品", width : 200, align: 'left'}
    ],
    buttons : [
        {name: "删除", bclass: "delete", onpress : "scratch.scratchDelete"}
    ],
    showTableToggleBtn: true
});

$(document).ready(function(){
    $('.flexigrid').css('display','none');
})

var accTypeHtml = '<div id="accType">' +
        '当月累计签到&nbsp;' +
        '<input style="width:38px" type="text" name = "dayNum" id="dayNum"  >' +
        '&nbsp;天,<span class="zpqy">&nbsp;赠&nbsp;' +
        '<input style="width:38px" type="text" name = "point" id="point">&nbsp;积分</span> &nbsp;<input class="btn" type="button" value="添加" onclick="Signed.addLine(\'accType\')">' +
        '</div>';

var conTypeHtml = '<div id="conType">' +
        '当月连续签到&nbsp;' +
        '<input style="width:38px" type="text" name = "signedDayNum" id="signedDayNum"  >' +
        '&nbsp;~&nbsp;<input style="width:38px"  type="text" name = "signedEndDayNum" id="signedEndDayNum"  >' +
        '&nbsp;天,<span class="zpqy">每天赠&nbsp;' +
        '<input style="width:38px" type="text" name = "point" id="point">&nbsp;积分</span> &nbsp;<input class="btn" type="button" value="添加" onclick="Signed.addLine(\'conType\')">' +
        '</div>';

var accTypeGoodsHtml = '<div id ="accTypeGoods">' +
        '当月累计签到&nbsp;' +
        '<input style="width:38px" type="text" name = "dayNum" id="dayNum"  >&nbsp;天,' +
        '<input type="text" name = "goodsName" id="goodsName" value="请输入赠品名称"> &nbsp;<input class="btn" type="button" value="添加" onclick="Signed.addLine(\'accTypeGoods\')">' +
        '</div>';

var conTypeGoodsHtml = '<div id ="conTypeGoods">' +
        '当月连续签到&nbsp;' +
        '<input style="width:38px" type="text" name = "signedDayNum" id="signedDayNum"  >' +
        '&nbsp;~&nbsp;<input style="width:38px"  type="text" name = "signedEndDayNum" id="signedEndDayNum"  >' +
        '&nbsp;天,<span class="zpqy">' +
        '<input type="text" name = "goodsName" id="goodsName" value="请输入赠品名称"></span> &nbsp;<input class="btn" type="button" value="添加" onclick="Signed.addLine(\'conTypeGoods\')">' +
        '</div>';



var Signed = {

    //判断签到活动类型
    signedType: function(ythis,typeId){

        if(!ythis.checked){
            //却换的时候清空Table数据 重置MARK
            table_obj.rows = new Array();
            mark = 0;
            mark1 = 0;
            mark2 = 0;
            mark3 = 0;
            Signed.addLine('');
        }

        if(ythis.checked){



            if(typeId == 'accType' && $(":radio[name = gift]:checked").val() == 1){

                $('#conType').remove();
                $('#accTypeGoods').remove();
                $('#conTypeGoods').remove();

                $('#hiddenBox').html(accTypeHtml);
            }

            if(typeId == 'accType' && $(":radio[name = gift]:checked").val() == 2){

                $('#conType').remove();
                $('#accType').remove();
                $('#conTypeGoods').remove();

                $('#hiddenBox').html(accTypeGoodsHtml);
            }


            if(typeId == 'conType' && $(":radio[name = gift]:checked").val() == 1){

                $('#accType').remove();
                $('#conTypeGoods').remove();
                $('#accTypeGoods').remove();

                $('#hiddenBox').html(conTypeHtml);

            }

            if(typeId == 'conType' && $(":radio[name = gift]:checked").val() == 2){

                $('#conType').remove();
                $('#accType').remove();
                $('#accTypeGoods').remove();

                $('#hiddenBox').html(conTypeGoodsHtml);

            }

        }
    },
    //判断活动礼品类型
    goodsType:function(ythis,num){

        if(!ythis.checked){
            //却换的时候清空Table数据 重置MARK
            table_obj.rows = new Array();
            mark = 0;
            mark1 = 0;
            mark2 = 0;
            mark3 = 0;
            Signed.addLine('');
        }


        if(ythis.checked){

            if(num == 1 && $(":radio[name = conSigned]:checked").val() == 1){

                $('#accType').remove();
                $('#conTypeGoods').remove();
                $('#accTypeGoods').remove();

                $('#hiddenBox').html(conTypeHtml);
            }

            if(num == 1 && $(":radio[name = conSigned]:checked").val() == 2){

                $('#conType').remove();
                $('#accTypeGoods').remove();
                $('#conTypeGoods').remove();

                $('#hiddenBox').html(accTypeHtml);
            }

            if(num == 2 && $(":radio[name = conSigned]:checked").val() == 1){

                $('#conType').remove();
                $('#accType').remove();
                $('#accTypeGoods').remove();

                $('#hiddenBox').html(conTypeGoodsHtml);
            }

            if(num == 2 && $(":radio[name = conSigned]:checked").val() == 2){

                $('#conType').remove();
                $('#accType').remove();
                $('#conTypeGoods').remove();

                $('#hiddenBox').html(accTypeGoodsHtml);

            }

        }
    },

    addLine: function(type){

        if(type == ""){
            $("#flex").flexAddData(table_obj);
        }

        $('.flexigrid').css('display','');

        if(type == 'conType'){

            conTypeArr = new Array();
            var addline = [$('#signedDayNum').val()+'~'+$('#signedEndDayNum').val(),$('#point').val()];
            conTypeArr.push(addline);
            mark++;
            $.each(conTypeArr,function(k,v){
                table_obj.rows.push({'id':mark,'cell':v});
            })

            console.log(conTypeArr);

            $("#flex").flexAddData(table_obj);

        }

        if(type == 'accType'){

            accTypeArr = new Array();

            var addline = [$('#dayNum').val(),$('#point').val()];

            accTypeArr.push(addline);

            mark1++;

            $.each(accTypeArr,function(k,v){
                table_obj.rows.push({'id':mark1,'cell':v});
            })

            $("#flex").flexAddData(table_obj);

        }

        if(type == 'conTypeGoods'){

            conTypeGoodsArr = new Array();

            var addline = [$('#signedDayNum').val()+'~'+$('#signedEndDayNum').val(),$('#goodsName').val()];

            conTypeGoodsArr.push(addline);

            mark3++;

            $.each(conTypeGoodsArr,function(k,v){
                table_obj.rows.push({'id':mark3,'cell':v});
            })

            $("#flex").flexAddData(table_obj);

        }

        if(type == 'accTypeGoods'){

            accTypeGoodsArr = new Array();

            var addline = [$('#dayNum').val(),$('#goodsName').val()];

            accTypeGoodsArr.push(addline);

            mark2++;

            $.each(accTypeGoodsArr,function(k,v){
                table_obj.rows.push({'id':mark2,'cell':v});
            })

            $("#flex").flexAddData(table_obj);

        }

    },

    check: function(){
        console.log(accTypeArr);
        console.log(conTypeArr);
        console.log(conTypeGoodsArr);
        console.log(accTypeGoodsArr);
    }

    }



    cal.manageFields("startDate", "startDate", "%Y-%m-%d");
    cal.manageFields("endDate", "endDate", "%Y-%m-%d");


</script>

</body>

</html>
